<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

</head>
<body>
<div id="app">
    <el-table :data="arr" style="width: 100%">
        <el-table-column type="index" label="序号" width="180"></el-table-column>
        <el-table-column prop="id" label="ID" width="180" ></el-table-column>
        <el-table-column prop="name" label="姓名" width="180"></el-table-column>
        <el-table-column prop="job" label="工作" width="180"></el-table-column>
        <el-table-column prop="sal" label="薪资" width="180" ></el-table-column>
        <el-table-column label="操作">
            <!--scope是必须添加的属性值，封装了每一行的数据，
            scope.$index：对应行的下标，scope.row对应行的数据-->
            <template slot-scope="scope">
                <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
  let v = new Vue({
    el: '#app',
    data: function() {
      return {
          arr:[]
      }
    },
    methods:{
        handleEdit(index, row) {
            console.log(index, row);
        },
        //index:下标，row：所在行的数据
        handleDelete(index, row) {
            axios.post("/delete?id="+row.id).then(function () {
                location.reload();//刷新本页面
            })
        }
    },
      created(){
          axios.get("/select").then(function (response) {
              v.arr = response.data;
          })
      }
  })
</script>
</html>